#pragma once

#include "xutil/platform/socket.h"
#include "xutil/prefix.h"

// the stream ctrl
#define XU_STREAM_CTRL(type, ctrl) (((type) << 16) | (ctrl))
#define XU_STREAM_CTRL_FLTR(type, ctrl) XU_STREAM_CTRL(XU_STREAM_TYPE_FLTR, (((type) << 8) | (ctrl)))

// the stream default timeout, 10s
#define XU_STREAM_DEFAULT_TIMEOUT (10000)

// the stream mode enum
typedef enum __xu_stream_mode_e
{
    XU_STREAM_MODE_NONE = 0,
    XU_STREAM_MODE_AIOO = 1 ///!< for stream
    ,
    XU_STREAM_MODE_AICO = 2 ///!< for async_stream

} xu_stream_mode_e;

// the stream type enum
typedef enum __xu_stream_type_e
{
    XU_STREAM_TYPE_NONE = 0,
    XU_STREAM_TYPE_FILE = 1,
    XU_STREAM_TYPE_SOCK = 2,
    XU_STREAM_TYPE_HTTP = 3,
    XU_STREAM_TYPE_DATA = 4,
    XU_STREAM_TYPE_FLTR = 5,
    XU_STREAM_TYPE_USER = 6 ///!< for user defined stream type

} xu_stream_type_e;

// the stream wait enum
typedef enum __xu_stream_wait_e
{
    XU_STREAM_WAIT_NONE = XU_SOCKET_EVENT_NONE,
    XU_STREAM_WAIT_READ = XU_SOCKET_EVENT_RECV,
    XU_STREAM_WAIT_WRIT = XU_SOCKET_EVENT_SEND,
    XU_STREAM_WAIT_EALL = XU_SOCKET_EVENT_EALL

} xu_stream_wait_e;

// the stream ctrl enum
typedef enum __xu_stream_ctrl_e
{
    XU_STREAM_CTRL_NONE = 0

    // the stream
    ,
    XU_STREAM_CTRL_GET_URL     = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 1),
    XU_STREAM_CTRL_GET_HOST    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 2),
    XU_STREAM_CTRL_GET_PORT    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 3),
    XU_STREAM_CTRL_GET_PATH    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 4),
    XU_STREAM_CTRL_GET_SSL     = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 5),
    XU_STREAM_CTRL_GET_TIMEOUT = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 6),
    XU_STREAM_CTRL_GET_SIZE    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 7),
    XU_STREAM_CTRL_GET_OFFSET  = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 8)

        ,
    XU_STREAM_CTRL_SET_URL     = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 11),
    XU_STREAM_CTRL_SET_HOST    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 12),
    XU_STREAM_CTRL_SET_PORT    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 13),
    XU_STREAM_CTRL_SET_PATH    = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 14),
    XU_STREAM_CTRL_SET_SSL     = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 15),
    XU_STREAM_CTRL_SET_TIMEOUT = XU_STREAM_CTRL(XU_STREAM_TYPE_NONE, 16)

    // the stream for data
    ,
    XU_STREAM_CTRL_DATA_SET_DATA = XU_STREAM_CTRL(XU_STREAM_TYPE_DATA, 1)

    // the stream for file
    ,
    XU_STREAM_CTRL_FILE_GET_MODE  = XU_STREAM_CTRL(XU_STREAM_TYPE_FILE, 1),
    XU_STREAM_CTRL_FILE_SET_MODE  = XU_STREAM_CTRL(XU_STREAM_TYPE_FILE, 2),
    XU_STREAM_CTRL_FILE_AS_STREAM = XU_STREAM_CTRL(XU_STREAM_TYPE_FILE, 3),
    XU_STREAM_CTRL_FILE_GET_FILE  = XU_STREAM_CTRL(XU_STREAM_TYPE_FILE, 4)

    // the stream for sock
    ,
    XU_STREAM_CTRL_SOCK_GET_TYPE   = XU_STREAM_CTRL(XU_STREAM_TYPE_SOCK, 1),
    XU_STREAM_CTRL_SOCK_SET_TYPE   = XU_STREAM_CTRL(XU_STREAM_TYPE_SOCK, 2),
    XU_STREAM_CTRL_SOCK_KEEP_ALIVE = XU_STREAM_CTRL(XU_STREAM_TYPE_SOCK, 3),
    XU_STREAM_CTRL_SOCK_GET_SOCK   = XU_STREAM_CTRL(XU_STREAM_TYPE_SOCK, 4)

    // the stream for http
    ,
    XU_STREAM_CTRL_HTTP_GET_HEAD       = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 1),
    XU_STREAM_CTRL_HTTP_GET_RANGE      = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 2),
    XU_STREAM_CTRL_HTTP_GET_METHOD     = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 3),
    XU_STREAM_CTRL_HTTP_GET_VERSION    = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 4),
    XU_STREAM_CTRL_HTTP_GET_COOKIES    = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 5),
    XU_STREAM_CTRL_HTTP_GET_REDIRECT   = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 6),
    XU_STREAM_CTRL_HTTP_GET_HEAD_FUNC  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 7),
    XU_STREAM_CTRL_HTTP_GET_HEAD_PRIV  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 8),
    XU_STREAM_CTRL_HTTP_GET_AUTO_UNZIP = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 9),
    XU_STREAM_CTRL_HTTP_GET_POST_URL   = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 10),
    XU_STREAM_CTRL_HTTP_GET_POST_DATA  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 11),
    XU_STREAM_CTRL_HTTP_GET_POST_FUNC  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 12),
    XU_STREAM_CTRL_HTTP_GET_POST_PRIV  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 13),
    XU_STREAM_CTRL_HTTP_GET_POST_LRATE = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 14)

        ,
    XU_STREAM_CTRL_HTTP_SET_HEAD       = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 20),
    XU_STREAM_CTRL_HTTP_SET_RANGE      = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 21),
    XU_STREAM_CTRL_HTTP_SET_METHOD     = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 22),
    XU_STREAM_CTRL_HTTP_SET_VERSION    = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 23),
    XU_STREAM_CTRL_HTTP_SET_COOKIES    = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 24),
    XU_STREAM_CTRL_HTTP_SET_REDIRECT   = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 25),
    XU_STREAM_CTRL_HTTP_SET_HEAD_FUNC  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 26),
    XU_STREAM_CTRL_HTTP_SET_HEAD_PRIV  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 27),
    XU_STREAM_CTRL_HTTP_SET_AUTO_UNZIP = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 28),
    XU_STREAM_CTRL_HTTP_SET_POST_URL   = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 29),
    XU_STREAM_CTRL_HTTP_SET_POST_DATA  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 30),
    XU_STREAM_CTRL_HTTP_SET_POST_FUNC  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 31),
    XU_STREAM_CTRL_HTTP_SET_POST_PRIV  = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 32),
    XU_STREAM_CTRL_HTTP_SET_POST_LRATE = XU_STREAM_CTRL(XU_STREAM_TYPE_HTTP, 33)

    // the stream for filter
    ,
    XU_STREAM_CTRL_FLTR_GET_STREAM = XU_STREAM_CTRL(XU_STREAM_TYPE_FLTR, 1),
    XU_STREAM_CTRL_FLTR_GET_FILTER = XU_STREAM_CTRL(XU_STREAM_TYPE_FLTR, 2),
    XU_STREAM_CTRL_FLTR_SET_STREAM = XU_STREAM_CTRL(XU_STREAM_TYPE_FLTR, 3),
    XU_STREAM_CTRL_FLTR_SET_FILTER = XU_STREAM_CTRL(XU_STREAM_TYPE_FLTR, 4)

} xu_stream_ctrl_e;
